import Mock from 'mockjs'

const success = (msg, data) => {
    return {
        code: 0,
        data,
        msg
    }
}

const error = (msg, data) => {
    return {
        code: 1001,
        data,
        msg
    }
}

Mock.mock('/test/api/xxx/api/user/login', loginRes)

function loginRes(req) {
    // eslint-disable-next-line no-restricted-syntax
    console.log(req.body)
    const { user_name, password } = JSON.parse(req.body)
    if (user_name === 'weiqi' && password === '0214') {
        return success('登陆成功', {token: 'song'});
    } else {
        return error('登录失败', 1001)
    }
    // return
}

Mock.mock('/test/api/xxx/api/user/get_info', loginGetInfo)

function loginGetInfo() {
    return success('获取信息成功', {
        name: 'taosong',
        email: 'taosong.email'
    })
    // return
}

Mock.mock('/test/api/xxx/api/user/logout', logout)

function logout() {
    return success('退出成功')
    // return
}

Mock.mock('/test/api/xxx/api/user/register', register)

function register(req) {
    // eslint-disable-next-line no-restricted-syntax
    const { user_name, phone, password } = JSON.parse(req.body)
    if (user_name === 'weiqi' && password === '0214' && phone === '18744521802') {
        return success('注册成功,即将前往登录页')
    }
}